package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * <p>
 * user 用户表 前端控制器
 * </p>
 *
 * @author xie
 * @since 2017-09-21
 */
@Controller
//@RequestMapping("/demo/user")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private RestTemplate restTemplate;


    @RequestMapping("/userList")
    @ResponseBody
    public List<User> userList(){

        return  userService.selectList(null);
    }

    @GetMapping("/user/{id}")
    public ResponseEntity<User> findUserById(@PathVariable int id){
        return restTemplate.getForEntity("http://127.0.0.1:8080/"+id,User.class);
    }
	
}
